home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / dev / debug / Blowup.lha / source / dump.c < prev    next >
C/C++ Source or Header  |  1998-04-18  |  3KB  |  130 lines

  1. /*
  2.  * $Id: dump.c 1.3 1998/04/18 15:44:58 olsen Exp olsen $
  3.  *
  4.  * :ts=4
  5.  *
  6.  * Blowup -- Catches and displays task errors
  7.  *
  8.  * Written by Olaf `Olsen' Barthel <olsen@sourcery.han.de>
  9.  * Public Domain
  10.  */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "global.h"
  14. #endif    /* _GLOBAL_H */
  15.  
  16. /******************************************************************************/
  17.  
  18. STATIC VOID
  19. DumpRange(
  20.     const STRPTR    header,
  21.     const ULONG *    range,
  22.     int                numRangeLongs,
  23.     BOOL            check)
  24. {
  25.     int i;
  26.  
  27.     /* dump and check a range of long words. */
  28.     for(i = 0 ; i < numRangeLongs ; i++)
  29.     {
  30.         if((i % 8) == 0)
  31.         {
  32.             DPrintf("%s:",header);
  33.         }
  34.  
  35.         DPrintf(" %08lx",range[i]);
  36.  
  37.         if((i % 8) == 7)
  38.         {
  39.             DPrintf("\n");
  40.  
  41.             /* check every long word processed so far? */
  42.             if(check)
  43.             {
  44.                 UBYTE nameBuffer[MAX_FILENAME_LEN];
  45.                 ULONG segment;
  46.                 ULONG offset;
  47.                 int j;
  48.  
  49.                 for(j = i - 7 ; j <= i ; j++)
  50.                 {
  51.                     if(FindAddress(range[j],sizeof(nameBuffer),nameBuffer,&segment,&offset))
  52.                     {
  53.                         DPrintf("----> %08lx - \"%s\" Hunk %04lx Offset %08lx\n",
  54.                             range[j],nameBuffer,segment,offset);
  55.                     }
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
  61.  
  62. /******************************************************************************/
  63.  
  64. VOID
  65. VoiceComplaint(
  66.     UBYTE                    trap,
  67.     UWORD                    sr,
  68.     ULONG                    pc,
  69.     ULONG *                    stackFrame,
  70.     const STRPTR            format,
  71.                             ...)
  72. {
  73.     /* show the hit header, if there is one */
  74.     if(format != NULL)
  75.     {
  76.         UBYTE dateTimeBuffer[2*LEN_DATSTRING];
  77.         va_list varArgs;
  78.         struct timeval tv;
  79.  
  80.         GetSysTime(&tv);
  81.         ConvertTimeAndDate(&tv,dateTimeBuffer);
  82.         DPrintf("\n\aTASK TRAPPED\n%s\n",dateTimeBuffer);
  83.  
  84.         /* print the message to follow it */
  85.         va_start(varArgs,format);
  86.         DVPrintf(format,varArgs);
  87.         va_end(varArgs);
  88.     }
  89.  
  90.     /* show the stack frame, if there is one; this also includes
  91.      * a register dump.
  92.      */
  93.     if(stackFrame != NULL)
  94.     {
  95.         UBYTE nameBuffer[MAX_FILENAME_LEN];
  96.         struct Process * thisProcess;
  97.         ULONG segment;
  98.         ULONG offset;
  99.  
  100.         DPrintf("TRAP=0x%02lx  SR=0x%04lx  PC=0x%08lx  TCB=0x%08lx\n",trap,sr,pc,FindTask(NULL));
  101.         DumpRange("  PC",(ULONG *)pc,8,FALSE);
  102.         DumpRange("Data",stackFrame,8,DRegCheck);
  103.         DumpRange("Addr",&stackFrame[8],8,ARegCheck);
  104.         DumpRange("Stck",&stackFrame[16],8 * StackLines,StackCheck);
  105.  
  106.         /* show the name of the currently active process/task/whatever. */
  107.         thisProcess = (struct Process *)FindTask(NULL);
  108.         DPrintf("Name: \"%s\"",thisProcess->pr_Task.tc_Node.ln_Name);
  109.     
  110.         if(thisProcess->pr_Task.tc_Node.ln_Type == NT_PROCESS)
  111.         {
  112.             struct CommandLineInterface * cli;
  113.     
  114.             cli = BADDR(thisProcess->pr_CLI);
  115.             if(cli != NULL)
  116.             {
  117.                 if(cli->cli_CommandName != NULL)
  118.                     DPrintf("  CLI: \"%b\"",cli->cli_CommandName);
  119.             }
  120.         }
  121.  
  122.         if(FindAddress(pc,sizeof(nameBuffer),nameBuffer,&segment,&offset))
  123.         {
  124.             DPrintf("  \"%s\" Hunk %04lx Offset %08lx",nameBuffer,segment,offset);
  125.         }
  126.  
  127.         DPrintf("\n");
  128.     }
  129. }
  130.